package com.hhxy.string;

import java.util.Scanner;
import java.util.regex.Pattern;
//给手机号码设置隐私
public class PrivateNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String telephoneNumber;
        String pTelephoneNumber=null;
        boolean f = true;
        while(f){
            System.out.println("请您输入11位的电话号码：");
            telephoneNumber = sc.next();
            String reg = "^[1][3,5,7,8]\\d{9}$";
            if(!Pattern.matches(reg,telephoneNumber)){
                System.out.println("您输入的号码不正确，请重新输入！");
            }else{
                String before = telephoneNumber.substring(0,3);
                String after = telephoneNumber.substring(7);
                pTelephoneNumber = before+"****"+after;
                f=false;
            }
        }
        System.out.println(pTelephoneNumber);
    }
}
